<?php

namespace core;

class Container
{
    private static array $instance;

    public static function get(string $class): object
    {
        // 判断类是否存在
        if (!class_exists($class)) {
            throw new \InvalidArgumentException("Class {$class} does not exist.");
        }

        if (!isset(self::$instance[$class])) {
            self::$instance[$class] = new $class();
        }
        return self::$instance[$class];
    }
}
